<?php
  class download_excel{
      
      function __construct($filename){
           $this->namefile = $filename;
            #excel beginning declaration
            #start excel
            error_reporting(E_ALL);
            date_default_timezone_set('Europe/London');    
            require_once '../Classes/PHPExcel.php';
            $objReader = new PHPExcel_Reader_Excel5();
            $this->objPHPExcel= $objReader->load("".$this->namefile);    
            ini_set("memory_limit","-1");
      ##end of excel declarationi
      }
     
      function unload_excel(){
        #excel ending declaration
         #close excel        
             $this->objPHPExcel->disconnectWorksheets();                
             unset($this->objPHPExcel);       
        ##end of excel declaration
      } 
      
      function  set_cell_value($cell,$value){
         #insert directly to excel cell
         #@("b10","testing"); 
          $this->objPHPExcel->getActiveSheet()->setCellValue($cell,$value);
      }
      
      function set_column_row_value($column,$row,$value){
          #this inserts values to the cell by column and row
          #@("0","2","ako");
           $this->objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($column,$row,$value);  
       
      }
      
      function protect_sheet($password){
          #this protects the active sheet with a password
          #@("relan");
          $this->objPHPExcel->getActiveSheet()->getProtection()->setPassword($password);
          $this->objPHPExcel->getActiveSheet()->getProtection()->setSheet(true);
      }
      
      function hide_cell($row){
          #this hides a particular row
          #@("10");
          $this->objPHPExcel->getActiveSheet()->getRowDimension($row)->setVisible(false);
      }
      
      function save_to_server($folder_filename){
          #this will save the excel file to server folder
          #@("extra/relan.xls")
                $objWriter = new PHPExcel_Writer_Excel5($this->objPHPExcel);
                $objWriter->save($folder_filename);
      }
      
      function force_download($filename){ 
        #this force dowload the excel file to the browser
        #@("Relan") 
        #clean the headrs sent and force the output   
          if (ob_get_contents()!='') {
                ob_clean();
           }   
             header('Content-Type: application/vnd.ms-excel');
             header('Content-Disposition: attachment;filename="'.$filename.'.xls');
             header('Cache-Control: max-age=0');
               
              $objWriter = PHPExcel_IOFactory::createWriter($this->objPHPExcel, 'Excel5');
              $objWriter->save('php://output');
              ob_end_flush();
        
      }      
  }
?>
